/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package iteracon.tuple.iterator;

import java.util.ListIterator;
import iteracon.tuple.Tpl;

/**
 * list iterator for tuple
 * @author martin
 */
public class TupleListIterator<T> implements ListIterator<T>{
  private final Tpl<T> _t;
  private int _index;
  /**
   * constructor
   * @param t as type
   * @param index as start index
   */
  public TupleListIterator(Tpl<T> t, int index){
    _t = t;
    _index=index;
  }
  
  @Override
  public boolean hasNext() {
    return _index < _t.size()-1;
  }

  @Override
  public T next() {
    return _t.get(++_index);
  }

  @Override
  public void remove() {
    throw new UnsupportedOperationException("tuple is immutable");
  }

  @Override
  public boolean hasPrevious() {
    return _index>0;
  }

  @Override
  public T previous() {
    return _t.get(--_index);
  }

  @Override
  public int nextIndex() {
    return _index+1;
  }

  @Override
  public int previousIndex() {
    return _index-1;
  }

  @Override
  public void set(T e) {
    throw new UnsupportedOperationException("tuple is immutable");
  }

  @Override
  public void add(T e) {
    throw new UnsupportedOperationException("tuple is immutable");
  }

}
